//
//  RegisterController.m
//  collection
//
//  Created by 靖 张 on 12/18/11.
//  Copyright (c) 2011 Tsinghua University. All rights reserved.
//

#import "RegisterController.h"

@interface RegisterController()

@property (retain, nonatomic) IBOutlet UITableView *contentTableView;
@property (nonatomic, strong) IBOutlet  UITextField*    userNameTextField;
@property (nonatomic, strong) IBOutlet  UITextField*    nicknameTextField;
@property (nonatomic, strong) IBOutlet  UITextField*    passwordTextField;
@property (nonatomic, strong) IBOutlet  UITextField*    passCheckTextField;

- (IBAction)onClickCancelButton:(id)sender;
- (IBAction)onClickRegisterButton:(id)sender;


@end

@implementation RegisterController

@synthesize contentTableView = _contentTableView;
@synthesize userNameTextField   = _userNameTextField;
@synthesize nicknameTextField   = _nicknameTextField;
@synthesize passwordTextField   = _passwordTextField;
@synthesize passCheckTextField  = _passCheckTextField;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.contentTableView.backgroundColor = [UIColor clearColor];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"all_bg"]];
}

- (void)viewDidUnload
{
    [self setContentTableView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"RegisterCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        
        cell.indentationLevel = 1;
        cell.indentationWidth = 15.0f;
    }
    
    // Configure the cell...
    cell.textLabel.font = [UIFont boldSystemFontOfSize:16.0f];
    // User name
    int startX = 120;
    if (indexPath.row == 0) {
        cell.textLabel.text = @"帐       号：";
        CGRect frame;
        frame.origin.x      = startX;
        frame.origin.y      = 0;
        frame.size.width    = cell.frame.size.width - startX;
        frame.size.height   = cell.frame.size.height;
        self.userNameTextField.frame = frame;
        [cell addSubview:self.userNameTextField];
        [self.userNameTextField release];
    }
    else if (indexPath.row == 1) {
        cell.textLabel.text = @"昵       称：";
        CGRect frame;
        frame.origin.x      = startX;
        frame.origin.y      = 0;
        frame.size.width    = cell.frame.size.width - startX;
        frame.size.height   = cell.frame.size.height;
        self.nicknameTextField.frame = frame;
        [cell addSubview:self.nicknameTextField];
        [self.nicknameTextField release];
    }
    else if (indexPath.row == 2) {
        cell.textLabel.text = @"密       码：";
        CGRect frame;
        frame.origin.x      = startX;
        frame.origin.y      = 0;
        frame.size.width    = cell.frame.size.width - startX;
        frame.size.height   = cell.frame.size.height;
        self.passwordTextField.frame = frame;
        [cell addSubview:self.passwordTextField];
        [self.passwordTextField release];
    }
    else if(indexPath.row == 3) {
        cell.textLabel.text = @"确认密码：";
        CGRect frame;
        frame.origin.x      = startX;
        frame.origin.y      = 0;
        frame.size.width    = cell.frame.size.width - startX;
        frame.size.height   = cell.frame.size.height;
        self.passCheckTextField.frame = frame;
        [cell addSubview:self.passCheckTextField];
        [self.passCheckTextField release];
    }
    
    return cell;
}

#pragma mark - Private methods

- (IBAction)onClickRegisterButton:(id)sender {
    
}

- (IBAction)onClickCancelButton:(id)sender {
    
    [self dismissModalViewControllerAnimated:YES];
}

- (void)dealloc {
    [_contentTableView release];
    [super dealloc];
}
@end
